import { followUp } from '@/api/handle'
import moment from 'moment'

//跟进0、关闭预警1、解除预警2
export function followUpSubmit(type) {
  let row = this.row
  if (type) { // 关闭/解除
    let content =
      type == 1
        ? `关闭预警后，该信息不允许再跟进，是否确认关闭？
            关闭预警的信息将在“预警查询”列表中展示。`
        : `
            解除预警后，该信息不允许再跟进，是否确认解除？
            解除预警的信息将在“预警查询”列表中展示。`

    this.$confirm(content, '提示信息', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'info'
    })
      .then((action) => {
        let params = {
          warningCode: row.warningCode,
          content: (type == 1 ? '关闭' : '解除') + '预警',
          followUpTime: moment().format('YYYY-MM-DD HH:mm:ss'),
          type
        }
        followUp(params).then((res) => {
          if (!res.success) return
          let msg = (type == 1 ? '关闭' : '解除') + '预警成功'
          this.$message.success(msg)
          if (this.$route.path == '/warning/track/detail') {
            this.$router.go(-1)
          } else {
            this.visible = false
            this.handleSearch && this.handleSearch()
            this.detail && this.detail()
          }
        })
      })
      .catch(() => { })
  } else { // 跟进
    let params = {
      type,
      warningCode: row.warningCode,
      content: row.content,
      followUpTime: row.followUpTime + ' 00:00:00'
    }
    followUp(params).then((res) => {
      if (!res.success) return
      this.$message.success('跟进成功')
      this.visible = false
      this.handleSearch && this.handleSearch()
      this.detail && this.detail()
    })
  }
}